
// import oimo.collision.geometry.RayCastHit;
// import oimo.collision.narrowphase.detector.gjkepa.GjkEpa;
// import oimo.common.Setting;
// import oimo.common.Transform;
// import oimo.common.Vec3;
// import oimo.m.Vec3;
// import oimo.m.M;

import { Geometry } from "./Geometry";
import { Setting } from "../../common/Setting";
import { Vec3 } from "../../common/Vec3";
import { Transform } from "../../common/Transform";
import { RayCastHit } from "./RayCastHit";
import { GjkEpa } from "../narrowphase/detector/gjkepa/GjkEpa";

/**
 * Abstract class of the convex collision geometries supported by GJK/EPA collision detection.
 */

export class ConvexGeometry extends Geometry {
	// TODO: divide margin into "inner" margin and "outer" margin
	_gjkMargin: number;
	_useGjkRayCast: boolean;


	constructor(type: number) {
		super(type);
		this._gjkMargin = Setting.defaultGJKMargin;
		this._useGjkRayCast = false;
	}

	/**
	 * Returns the GJK mergin around the "core" of the convex geometry.
	 */
	public getGjkMergin(): number {
		return this._gjkMargin;
	}

	/**
	 * Sets the GJK mergin around the "core" to `gjkMergin`.
	 */
	public setGjkMergin(gjkMergin: number): void {
		if (gjkMergin < 0) gjkMergin = 0;
		this._gjkMargin = gjkMergin;
	}

	/**
	 * Computes supporting vertex of the "core" of the geometry in local coordinates.
	 * Note that the direction vector `dir` might not be normalized. `out` is set to
	 * the computed supporting vertex.
	 */
	public computeLocalSupportingVertex(dir: Vec3, out: Vec3): void {
	}

	public rayCast(begin: Vec3, end: Vec3, transform: Transform, hit: RayCastHit): boolean {
		if (this._useGjkRayCast) {
			return GjkEpa.getInstance().rayCast(this, transform, begin, end, hit);
		} else {
			return super.rayCast(begin, end, transform, hit);
		}
	}
}
